package com.zb;

import com.zb.repository.SkuRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class SearchApplication {

   /* public static void main(String[] args) {
        SpringApplication.run(SearchApplication.class,args);
    }*/
    public static void main(String[] args) throws Exception {



        ConfigurableApplicationContext run = SpringApplication.run(SearchApplication.class, args);
        SkuRepository skuRepository = run.getBean(SkuRepository.class);

        /*Map<String, String> param = new HashMap<>();
        param.put("keyword", "手机");
        param.put("index", "1");
        param.put("size", "50");
        param.put("brand", "小米,华为");
        param.put("cate", "手机");

        param.put("spec_颜色","黑色");
        param.put("spec_版本","6GB+64GB");

        param.put("price", "10000-20000");
//        param.put("price","20000-*");
//       param.put("price","*-20000");

        param.put("sortField", "price");
        param.put("sortRule", "asc");


        Map<String, Object> search = skuRepository.search(param);
        String count = search.get("totalHits").toString();
        System.out.println(count);

        List<String> brandList = (List<String>) search.get("brandList");
        for (String s : brandList) {
            System.out.println(s);
        }
        System.out.println("--------------------------");
        List<String> cateList = (List<String>) search.get("cateList");
        for (String s : cateList) {
            System.out.println(s);
        }
        System.out.println("--------------------------");
        Map<String, Set<String>> specMap = (Map<String, Set<String>>) search.get("specMap");
        for (Map.Entry<String, Set<String>> entry : specMap.entrySet()) {
            System.out.println(entry.getKey() + "\t" + entry.getValue());
        }
        System.out.println("--------------------------");
        List<Map<String, Object>> skuList =
                (List<Map<String, Object>>) search.get("skuList");
        for (Map<String, Object> map : skuList) {
            System.out.println(map);
        }*/
        skuRepository.importData();
        // skuRepository.createIndex();
    }
}
